home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _utilities / utilities / 001 / meschach / !Meschach / c / iotort < prev    next >
Text File  |  1994-08-04  |  3KB  |  147 lines

  1.  
  2. /**************************************************************************
  3. **
  4. ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  5. **
  6. **                 Meschach Library
  7. ** 
  8. ** This Meschach Library is provided "as is" without any express 
  9. ** or implied warranty of any kind with respect to this software. 
  10. ** In particular the authors shall not be liable for any direct, 
  11. ** indirect, special, incidental or consequential damages arising 
  12. ** in any way from use of the software.
  13. ** 
  14. ** Everyone is granted permission to copy, modify and redistribute this
  15. ** Meschach Library, provided:
  16. **  1.  All copies contain this copyright notice.
  17. **  2.  All modified copies shall carry a notice stating who
  18. **      made the last modification and the date of such modification.
  19. **  3.  No charge is made for this software or works derived from it.  
  20. **      This clause shall not be construed as constraining other software
  21. **      distributed on the same medium as this software, nor is a
  22. **      distribution fee considered a charge.
  23. **
  24. ***************************************************************************/
  25.  
  26. /* iotort.c  10/11/93 */
  27. /* test of I/O functions */
  28.  
  29.  
  30. static char rcsid[] = "$Id: $";
  31.  
  32. #include "sparse.h"
  33. #include "zmatrix.h"
  34.  
  35.  
  36. #define    errmesg(mesg)    printf("Error: %s error: line %d\n",mesg,__LINE__)
  37. #define notice(mesg)    printf("# Testing %s...\n",mesg);
  38.  
  39. #ifdef RISC_OS
  40. #define FILENAME "iotort_dat"
  41. #else
  42. #define FILENAME "iotort.dat"
  43. #endif
  44.  
  45. void main()
  46. {
  47.    VEC *x;
  48.    MAT *A;
  49.    PERM *pivot;
  50.    IVEC *ix;
  51.    SPMAT *spA;
  52.    ZVEC *zx;
  53.    ZMAT *ZA;
  54.    char yes;
  55.    int i;
  56.    FILE *fp;
  57.  
  58.    mem_info_on(TRUE);
  59.  
  60.    if ((fp = fopen(FILENAME,"w")) == NULL) {
  61.       printf(" !!! Cannot open file %s for writing\n\n",FILENAME);
  62.       exit(1);
  63.    }
  64.      
  65.    x = v_get(10);
  66.    A = m_get(3,3);
  67.    zx = zv_get(10);
  68.    ZA = zm_get(3,3);
  69.    pivot = px_get(10);
  70.    ix = iv_get(10);
  71.    spA = sp_get(3,3,2);
  72.  
  73.    v_rand(x);
  74.    m_rand(A);
  75.    zv_rand(zx);
  76.    zm_rand(ZA);
  77.    px_ident(pivot);
  78.    for (i=0; i < 10; i++)
  79.      ix->ive[i] = i+1;
  80.    for (i=0; i < spA->m; i++) {
  81.       sp_set_val(spA,i,i,1.0);
  82.       if (i > 0) sp_set_val(spA,i-1,i,-1.0);
  83.    }
  84.  
  85.    notice(" VEC output");
  86.    v_foutput(fp,x);
  87.    notice(" MAT output");
  88.    m_foutput(fp,A);
  89.    notice(" ZVEC output");
  90.    zv_foutput(fp,zx);
  91.    notice(" ZMAT output");
  92.    zm_foutput(fp,ZA);
  93.    notice(" PERM output");
  94.    px_foutput(fp,pivot);
  95.    notice(" IVEC output");
  96.    iv_foutput(fp,ix);
  97.    notice(" SPMAT output");
  98.    sp_foutput(fp,spA);
  99.    fprintf(fp,"Y");
  100.    fclose(fp);
  101.  
  102.    printf("\nENTER SOME VALUES:\n\n");
  103.  
  104.    if ((fp = fopen(FILENAME,"r")) == NULL) {
  105.       printf(" !!! Cannot open file %s for reading\n\n",FILENAME);
  106.       exit(1);
  107.    }
  108.  
  109.    notice(" VEC input/output");
  110.    x = v_finput(fp,x);
  111.    v_output(x);
  112.  
  113.    notice(" MAT input/output");
  114.    A = m_finput(fp,A);
  115.    m_output(A);
  116.  
  117.    notice(" ZVEC input/output");
  118.    zx = zv_finput(fp,zx);
  119.    zv_output(zx);
  120.  
  121.    notice(" ZMAT input/output");
  122.    ZA = zm_finput(fp,ZA);
  123.    zm_output(ZA);
  124.  
  125.    notice(" PERM input/output");
  126.    pivot = px_finput(fp,pivot);
  127.    px_output(pivot);
  128.  
  129.    notice(" IVEC input/output");
  130.    ix = iv_finput(fp,ix);
  131.    iv_output(ix);
  132.  
  133.    notice(" SPMAT input/output");
  134.    SP_FREE(spA);
  135.    spA = sp_finput(fp);
  136.    sp_output(spA);
  137.  
  138.    notice(" general input");
  139.    finput(fp," finish the test?  ","%c",&yes);
  140.    if (yes == 'y' || yes == 'Y' )
  141.      printf(" YES\n");
  142.    else printf(" NO\n");
  143.    fclose(fp);
  144.  
  145.    mem_info();
  146. }
  147.